[slug].vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <script lang='ts' setup>
  2. import { useCommonStore } from '@/stores/modules/common'
  3. import { Api } from '@/api/model/url'
  4. const route = useRoute()
  5. const commonStore = useCommonStore()
  6. const list = ref<any>([])
  7. const slug = route.params.slug
  8. const { data: res } = await useAsyncData(
  9. 'category-detail',
  10. () =>
  11. $fetch(`${process.env.MY_ENV_DEV_URL}${Api.CategoryDetail}`, { params: { slug } }),
  12. )
  13. const seoData = res.value?.result
  14. const { data: res2 } = await useAsyncData(
  15. 'category-catalogue-list',
  16. () =>
  17. $fetch(`${process.env.MY_ENV_DEV_URL}${Api.CategoryCatalogueList}`, { params: { slug } }),
  18. )
  19. list.value = res2.value?.result?.records || []
  20. const { openLoginAndDownloadModal } = useLoginAndDownLoadModal()
  21. async function clickLoginAndDownload(item: any) {
  22. try {
  23. commonStore.setDownloadCatalog(item)
  24. const { status } = await openLoginAndDownloadModal()
  25. if (status)
  26. location.reload()
  27. }
  28. catch (error) {
  29. console.log(error)
  30. }
  31. }
  32. const firstTitle = computed(() => {
  33. return seoData?.contentTitle ? handleTitle(seoData.contentTitle, 1) : ''
  34. })
  35. const secondTitle = computed(() => {
  36. return seoData?.contentTitle ? handleTitle(seoData.contentTitle, 2) : ''
  37. })
  38. function handleTitle(title: string | undefined, position: number) {
  39. if (!title)
  40. return ''
  41. // 先判断标题中是否带有&,获取第一个&之前的数据和之后的数据
  42. let firstPart = ''
  43. let secondPart = ''
  44. const index = title.indexOf('&')
  45. if (index !== -1) {
  46. firstPart = title.slice(0, index).trim()
  47. secondPart = title.slice(index + 1).trim()
  48. }
  49. else {
  50. // 如果没有&,返回第一个空格之前的数据和之后的数据
  51. const spaceIndex = title.indexOf(' ')
  52. if (spaceIndex !== -1) {
  53. firstPart = title.slice(0, spaceIndex).trim()
  54. secondPart = title.slice(spaceIndex + 1).trim()
  55. }
  56. }
  57. return position === 1 ? firstPart : secondPart || ''
  58. }
  59. </script>
  60. <template>
  61. <div>
  62. <div class=" bg-#0F0820 header">
  63. <div class=" w-1200-auto pos-relative text-center flex items-center justify-start h-600px bg-no-repeat bg-center">
  64. <h1 class="text-58px fw-800 text-#fff ls-2 custom-title-font">
  65. <span class="flex items-center">
  66. {{ firstTitle }}<svgo-flower class="w-44px h-44px !text-#FFFF66 ml-20px" />
  67. </span>
  68. <span class="flex items-center">
  69. <svgo-star-blue class="w-44px h-44px text-#1AC18E mr-20px" /> {{ secondTitle }}
  70. </span>
  71. </h1>
  72. <div class="pos-absolute right-0 bottom-76px w-426px h-340px header-img-bg flex justify-center items-center">
  73. <img :src="seoData.bannerImg" alt="" class="w-full h-390px object-contain mb-40px">
  74. </div>
  75. </div>
  76. </div>
  77. <div class="py-120px w-1200-auto text-center">
  78. <h2 class="text-36px fw-800 text-#333 !mb-20px custom-title-font">
  79. Our Latest Product <span class="custom-title-bg04">Catalogs</span>
  80. </h2>
  81. <div class="text-#999 text-22px mb-40px">
  82. Discover bestsellers and fresh arrivals tailored to your niche.
  83. </div>
  84. <div class="grid grid-cols-2 gap-64px text-left">
  85. <div v-for="item in list" :key="item.id">
  86. <business-categories-comp-item :item="item" @select="clickLoginAndDownload" />
  87. </div>
  88. </div>
  89. </div>
  90. <common-block-catalogs />
  91. <common-block-blog class="!pb-0" />
  92. <AppFooter />
  93. </div>
  94. </template>
  95. <style lang='less' scoped>
  96. .header{
  97. background-image: url('@/assets/images/catalogue_bg.png');
  98. background-position: center center;
  99. background-size: cover;
  100. .header-img-bg{
  101. background-image: url('@/assets/images/catalogue_bg_img.png');
  102. background-size: cover;
  103. background-position: center;
  104. }
  105. }
  106. </style>